/**
 * @file Parameter.cpp
 * @author enemy1205 (enemy1205@qq.com)
 * @brief 参数管理类
 * @date 2021-08-16
 *
 */

#include "Parameter.h"

using namespace cv;
using namespace std;

LightBlobParam::LightBlobParam(const string &path) {
    FileStorage fsLB(path, FileStorage::READ);
    // Filter lights
    fsLB["MIN_AREA"] >> min_area;
    fsLB["LIGHT_MIN_LENGTH"] >> light_min_length;
    fsLB["FAR_MAX_LENGTH"] >> far_max_length;
    fsLB["FAR_MAX_RATIO"] >> far_max_ratio;
    fsLB["FAR_MIN_RATIO"] >> far_min_ratio;
    fsLB["LIGHT_MIN_AREA"] >> light_min_area;
    fsLB["LIGHT_MAX_RATIO"] >> light_max_ratio;
    fsLB["LIGHT_MIN_AREA_RATIO"] >> light_min_area_ratio;
    fsLB["LIGHT_MAX_ANGLE"] >> light_max_angle;
    fsLB["ERR_AREA_RATIO"] >> ERR_AREA_RATIO;
    fsLB["ERR_ANGLE"] >> ERR_ANGLE;
}

ArmorParam::ArmorParam(const string &path) {
    FileStorage fsA(path, FileStorage::READ);
    //预处理
    fsA["THREAD"] >> threshold;
    //灯条匹配
    fsA["LIGHT_MAX_ANGLE_DIFF"] >> light_max_angle_diff;
    fsA["LIGHT_MAX_HEIGHT_RATIO"] >> light_max_height_ratio;
    fsA["LIGHT_MAX_WIDTH_RATIO"] >> light_max_width_ratio;
    fsA["MAX_UP_DOWN_DIS_RATIO"] >> max_up_down_dis_ratio;
    //装甲板过滤
    fsA["ARMOR_MAX_RATIO"] >> armor_max_ratio;
    fsA["ARMOR_MIN_RATIO"] >> armor_min_ratio;
    fsA["ARMOR_MAX_ANGLE"] >> armor_max_angle;
    fsA["BIG_ARMOR_MAX_RATIO"] >> BIG_armor_max_ratio;
    fsA["BIG_ARMOR_MIN_RATIO"] >> BIG_armor_min_ratio;
    fsA["MAX_DIG_WIDTH_RATIO"] >> max_dig_width_ratio;
    fsA["MIN_DIG_WIDTH_RATIO"] >> min_dig_width_ratio;
    fsA["ERROR_ANGLE_DIFF"] >> ERROR_ANGLE_DIFF;
    fsA["ERROR_ANGLE"] >> ERROR_ANGLE;
    fsA["ERROR_H_W_RATIO"] >> ERROR_H_W_RATIO;
    fsA["ERROR_WH_RATIO"] >> ERROR_WH_RATIO;
    fsA["ERROR_DIG_WIDTH"] >> ERROR_DIG_WIDTH;
    //匹配序列判断参数
    fsA["MAX_DELTA_DIS"] >> MAX_DELTA_DIS;
    fsA["MAX_DELTA_DIS_RATIO"] >> MAX_DELTA_DIS_RATIO;
    fsA["MAX_DIRECTION_RATIO"] >> MAX_DIRECTION_RATIO;
    //装甲板追踪参数
    fsA["SEQ_MAXLENGTH"] >> Seq_maxlength;
    fsA["EXTEND_K"] >> extend_k;
    fsA["PREDICT_CONFIDENCE"] >> predictConfidence;
}

RuneParam::RuneParam(const string &path) {
    FileStorage fsR(path, FileStorage::READ);
    //预处理
    fsR["THREAD"] >> threshold;
    fsR["K_SIZE"] >> ksize;
    //神符尺寸
    fsR["R_MINAREA"] >> R_minarea;
    fsR["R_MAXAREA"] >> R_maxarea;
    fsR["MAX_RUNE_CENTER_RATIO"] >> Max_Rune_center_ratio;
    fsR["MIN_RUNE_CENTER_RATIO"] >> Min_Rune_center_ratio;
    //神符装甲板尺寸
    fsR["MIN_LW_RATIO"] >> min_lw_ratio;
    fsR["MAX_LW_RATIO"] >> max_lw_ratio;
    //神符追踪参数
    fsR["RECORD_FRAMES"] >> RECORD_FRAMES;
    fsR["MAX_DELTA_ANGLE"] >> MAX_DELTA_ANGLE;
}

CameraParam::CameraParam(const string &path) {
    cv::FileStorage Fs(path, cv::FileStorage::READ);
    Fs["cam_exposure"] >> cam_exposure;
    Fs["cam_contrast"] >> cam_contrast;
    Fs["cam_gamma"] >> cam_gamma;
    Fs["cam_Bgain"] >> cam_Bgain;
    Fs["cam_Ggain"] >> cam_Ggain;
    Fs["cam_Rgain"] >> cam_Rgain;
    Fs["camera_matrix"] >> cameraMatrix;
    Fs["distortion_coefficients"] >> distCoeff;
}

KalmanFilterParam::KalmanFilterParam(const string &path) {
    cv::FileStorage Fs(path, cv::FileStorage::READ);
    Fs["GYRO_PROCESS_ERROR"] >> GYRO_PROCESS_ERROR;
    Fs["GYRO_MEASURE_ERROR"] >> GYRO_MEASURE_ERROR;
    Fs["DIS_PROCESS_ERROR"] >> DIS_PROCESS_ERROR;
    Fs["DIS_MEASURE_ERROR"] >> DIS_MEASURE_ERROR;
    Fs["ANGLE_PROCESS_ERROR"] >> ANGLE_PROCESS_ERROR;
    Fs["ANGLE_MEASURE_ERROR"] >> ANGLE_MEASURE_ERROR;
}

StrategyParam::StrategyParam(const string &path) {
    FileStorage strategy(path, FileStorage::READ);
    strategy["SENTRY_TRACK_FRAMES"] >> this->SENTRY_TRACK_FRAMES;
    strategy["NORMAL_TRACK_FRAMES"] >> this->NORMAL_TRACK_FRAMES;
    strategy["RECORD_FRAMES"] >> this->RECORD_FRAMES;
    strategy["MAX_DIS"] >> this->MAX_DIS;
    strategy["MAX_DIS_DIFF"] >> this->MAX_DIS_DIFF;
    strategy["GYRO_RADIUS_RATIO"] >> this->GYRO_RADIUS_RATIO;
    strategy["NORMAL_RADIUS_RATIO"] >> this->NORMAL_RADIUS_RATIO;
    strategy["SHOOT_CONFIDENCE_LEVEL"] >> this->SHOOT_CONFIDENCE_LEVEL;
    strategy["SHOOT_SPEED_15_BIAS"] >> this->SHOOT_SPEED_15_BIAS;
    strategy["SHOOT_SPEED_18_BIAS"] >> this->SHOOT_SPEED_18_BIAS;
    strategy["SHOOT_SPEED_30_BIAS"] >> this->SHOOT_SPEED_30_BIAS;
}

CompensateParam::CompensateParam(const string &path) {
    FileStorage Fs(path, FileStorage::READ);
    Fs["ITERATE_TIMES"] >> this->ITERATE_TIMES;
    Fs["ITERATE_ACCURACY"] >> this->ITERATE_ACCURACY;
    Fs["YAW_COMPENSATE"] >> this->YAW_COMPENSATE;
    Fs["RUNE_PITCH_COMPENSATE"] >> this->RUNE_PITCH_COMPENSATE;
    Fs["PITCH_COMPENSATE"] >> this->PITCH_COMPENSATE;
    Fs["WINDAGE_TIME_COMPENSATE"] >> this->WINDAGE_TIME_COMPENSATE;
}

OtherParam::OtherParam(const string &path) {
    cv::FileStorage Fs(path, cv::FileStorage::READ);
    Fs["TIME_PER_FRAME"] >> Time_per_frame;
    Fs["INIT_DETECT_MODE"] >> init_detect_mode;
    Fs["INIT_COLOR_MODE"] >> init_color_mode;
    Fs["INIT_PITCH"] >> init_pitch;
    Fs["INIT_YAW"] >> init_yaw;
    Fs["INIT_PITCH_SPEED"] >> init_pitch_speed;
    Fs["INIT_YAW_SPEED"] >> init_yaw_speed;
    Fs["INIT_SHOOT_SPEED"] >> init_shoot_speed;
    Fs["FLYING_TIME"] >> fly_time;
}
